package com.yanqu.road.server.logic.recharge.limit;

import com.yanqu.road.entity.config.goods.MallInfo;
import com.yanqu.road.entity.enums.eSystemId;
import com.yanqu.road.entity.mall.LimitBuyResult;
import com.yanqu.road.logic.config.GameConfig;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.player.SecretVolumeModule;
import com.yanqu.road.server.manger.player.GamePlayerMgr;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.webservice.GamePublicFunction;

public class SecretVolumeMallLimit extends BaseRMBMallLimit {
    private GamePlayer player;
    public SecretVolumeMallLimit(long userId, MallInfo mallInfo) {
        super(userId, mallInfo);
    }

    @Override
    protected int pretreatment() {
        GamePlayer player = GamePlayerMgr.getOnlinePlayer(userId);
        if(null == player){
            return GameErrorCode.E_MALL_LIMIT_BUY;
        }
        this.player = player;
        return super.pretreatment();
    }

    @Override
    protected boolean isSystemUnLock() {
        return GamePublicFunction.isSystemOpen(userId, eSystemId.SecretVolume.getValue());
    }

    @Override
    protected LimitBuyResult buyCountLimit() {
        LimitBuyResult limitBuyResult = new LimitBuyResult();
        limitBuyResult.setLimitCount(1);
        return limitBuyResult;
    }

    @Override
    protected int logicCheck() {
        if(mallInfo.getMallId() != GameConfig.SECRET_VOLUME_MALL_ID){
            return GameErrorCode.E_MALL_NO_EXIST;
        }
        if (!player.getModule(SecretVolumeModule.class).isNowInTime()) {
            return GameErrorCode.E_MALL_LIMIT_BUY;
        }
        if (player.getModule(SecretVolumeModule.class).isBuySecretVolume()) {//限购，财神密卷已购买
            return GameErrorCode.E_MALL_LIMIT_BUY;
        }
        return 0;
    }
}
